package day27;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class WorkClient2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Socket client = null;
        BufferedWriter bw = null;
        BufferedReader br = null;
        try {
            client = new Socket("127.0.0.1", 9999);
            bw = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
            br = new BufferedReader(new InputStreamReader(client.getInputStream()));
            while (true) {
                System.out.println("********");
                System.out.println("1.add");
                System.out.println("2.minus");
                System.out.println("3.multiply");
                System.out.println("4.divide");
                System.out.println("********");
                System.out.print("请输入对应的编号（加/减/乘/除）: ");
                String str = sc.nextLine();
                System.out.print("请输入第一个数:");
                double num1 = sc.nextDouble();
                sc.nextLine();
                System.out.print("请输入第二个数:");
                double num2 = sc.nextDouble();
                sc.nextLine();
                bw.write(str + " " + num1 + " " + num2 + "\n");
                bw.flush();
                String result = br.readLine();
                System.out.println("结果: " + result);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (bw != null) bw.close();
                if (br != null) br.close();
                if (client != null) client.close();
                sc.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}